package com.pricl.frame.core.log;

import java.sql.Connection;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;

import net.sf.log4jdbc.ConnectionSpy;
import net.sf.log4jdbc.SpyLogFactory;

/**
 *
 * <p>
 * TODO
 * </p>
 *
 * @author cheng(iknoweth@yahoo.com)
 * @date 2016-5-18 下午9:50:36
 */
public class DataSourceSpyInterceptor implements MethodInterceptor {

	@Override
	public Object invoke(MethodInvocation invocation) throws Throwable {
		Object result = invocation.proceed();
		if (SpyLogFactory.getSpyLogDelegator().isJdbcLoggingEnabled()) {
			if (result instanceof Connection) {
				Connection conn = (Connection) result;
				return new ConnectionSpy(conn);
			}
		}
		return result;
	}

}
